unit ColorsContainer;

interface

uses Graphics, Windows;

type

 ColorContainer = record
  Color: TColor;
  Value: Integer;
 end;

 TColorContainer = class
 private
  Colors: array of TColor;
  ColorsQuantity: Integer;
 public
  constructor Create(Quantity: Integer);
  function GetRandomColor: ColorContainer;
 end;

implementation

uses Math;

function TColorContainer.GetRandomColor: ColorContainer;
var
 Output: ColorContainer;
 i: integer;
begin
 i := Random(ColorsQuantity);
 Output.Color := Colors[i];
 Output.Value := i+1;   //we do not want to return a 0 value
 Result := Output;
end;

constructor TColorContainer.Create(Quantity: Integer);
var
 i: integer;
begin
 Self.ColorsQuantity := Quantity;
 SetLength(Colors, Quantity);

 for i := 0 to Quantity - 1 do
  Colors[i] := RGB(Random(256),Random(256),Random(256));
end;

end.
